package com.lianbang.pharmacy.adapter

import cn.ubest.mvvmcore.utils.ResourcesUtils
import cn.ubest.mvvmcore.utils.SpanUtils
import com.chad.library.adapter.base.BaseNodeAdapter
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.entity.node.BaseNode
import com.chad.library.adapter.base.provider.BaseNodeProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.lianbang.pharmacy.R
import com.lianbang.pharmacy.bean.ShopCarHeaderBean

/**
 * Created by maoqi on 2020/12/13.
 */
class ShopCarItemListAdapter2 : BaseNodeAdapter {

    constructor(nodeList: MutableList<BaseNode>? = null) : super(nodeList) {
        addChildClickViewIds(R.id.cb_check, R.id.btn_reduce, R.id.btn_add)
        // 需要占满一行的，使用此方法（例如section）
        addFullSpanNodeProvider(HeaderProvider())
        // 普通的item provider
        addNodeProvider(ItemProvider())
    }

    override fun getItemType(data: List<BaseNode>, position: Int): Int {
        val bean = data[position]
        return if (bean is ShopCarHeaderBean) {
            1
        } else {
            2
        }
    }

    class HeaderProvider : BaseNodeProvider() {
        override val itemViewType: Int
            get() = 1

        override val layoutId: Int
            get() = R.layout.header_shop_car_item_list

        override fun convert(helper: BaseViewHolder, item: BaseNode) {
            helper.setText(R.id.tv_title, "湖北药丰大药房有限公司")
        }
    }

    class ItemProvider : BaseNodeProvider() {
        override val itemViewType: Int
            get() = 2

        override val layoutId: Int
            get() = R.layout.item_shop_car_item_list

        override fun convert(helper: BaseViewHolder, item: BaseNode) {
            helper.setText(R.id.tv_title, "连花清瘟胶囊")
                .setText(R.id.tv_standard, "10mgx7片/盒")
                .setText(
                    R.id.tv_price,
                    SpanUtils()
                        .append("¥")
                        .append("136.00")
                        .setBold()
                        .setFontSize(14, true)
                        .create()
                )
                .setBackgroundColor(R.id.iv_img, ResourcesUtils.getColor(R.color.black))

        }
    }

}